<?php
namespace Common\Model;
use Think\Model;
class UserFavoritesModel extends Model
{
	
	protected $_validate = array(
		//array(验证字段,验证规则,错误提示,验证条件,附加规则,验证时间)
		array('car_id', 'require', '车辆ID不能为空！', 0, 'regex', CommonModel:: MODEL_BOTH  ),
	);
	
	protected $_auto = array(
	    array('create_time','mGetDate',CommonModel:: MODEL_INSERT,'callback'),
	);
	
	//用于获取时间，格式为2012-02-03 12:12:12,注意,方法不能为private
	function mGetDate() {
		return date('Y-m-d H:i:s');
	}

	function  getFavorite($uid = 0, $type = 0, $carId = 0)
	{
		$favorite = $this->where("user_id={$uid} and type={$type} and car_id={$carId} ")->find();
		if (is_array($favorite)) {
			return $favorite;
		} else {
			return false;
		}
	}
}

